package com.myccb.app.view.investment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.myccb.app.base.BaseActivity;
import com.myccb.app.R;
import com.myccb.app.widget.CommonToolBar;

/**
 * Created by freak on 17-12-9.
 */

public class DetailsActivity extends BaseActivity{
    private static final String ACTION_CLOSE_DIALOG = "REMOVE_DIALOG";
    WebView webView;
    int position;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final Intent intent = new Intent(this, DialogActivity.class);
        setContentView(R.layout.activity_details);

        CommonToolBar commonToolBar=findViewById(R.id.common_toolbar);
        Toolbar toolbar=commonToolBar.getToolbar();
        setSupportActionBar(toolbar);
        commonToolBar.setTitle("资讯");

        commonToolBar.setOnLeftButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.slide_out_right);
            }
        });

        webView=findViewById(R.id.webview);

        startActivity(intent);
        position = getIntent().getExtras().getInt("position");
        //webView = new WebView(DetailsActivity.this);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                //setContentView(webView);
                removeDialog();
            }
        });
        webView.loadUrl(DataSet.hashMaps.get(position).get("href"));
    }
    private void removeDialog() {
        Intent intent = new Intent(DetailsActivity.this, DialogActivity.class)
                .setAction(ACTION_CLOSE_DIALOG);
        startActivity(intent);
    }
}
